<template>
	<view class="fui-wrap">
		<fui-sticky>
			<view style="background-color: #fff;">
				<fui-segmented-control :height="84" @click="changeSegmented" :current="current" color="#000" activeColor="#0a8cdd" type="text" :values="segmented"></fui-segmented-control>
			</view>
		</fui-sticky>
		<fui-list>
			<fui-list-cell v-for="(item,index) in list" :key="index" @click="showButton(item,index)">
				<view class="item" v-if="current===0">
					<view class="line">
						<view class="hang">
							<fui-text text="车牌号：" color="#afafaf" :size="24"></fui-text>
							<platetype :plate_number="item.plate_number" :plate_type="item.plate_type"></platetype>
						</view>
						<view class="hang">
							<fui-text text="入场时间：" color="#afafaf" :size="24"></fui-text>
							<fui-text :text="item.entry_time_txt" color="#000" :size="28"></fui-text>
						</view>
					</view>
					<view class="line">
						<view class="hang">
							<fui-text text="停车状态：" color="#afafaf" :size="24"></fui-text>
							<fui-text :text="item.status_txt" :color="statusColor[item.status]" :size="28"></fui-text>
						</view>
						<view class="hang">
							<fui-text text="出场时间：" color="#afafaf" :size="24"></fui-text>
							<fui-text :text="item.exit_time_txt" color="#000" :size="28"></fui-text>
						</view>
					</view>
					<view class="line">
						<view class="hang">
							<fui-text text="停车费用：" color="#afafaf" :size="24"></fui-text>
							<fui-text :text="item.total_fee?`￥${parseNumber(item.total_fee)}`:``" color="#000" :size="28"></fui-text>
						</view>
						<view class="hang">
							<fui-text text="停车时长：" color="#afafaf" :size="24"></fui-text>
							<fui-text :text="formatDuration(item.park_time,'minutes')" color="#000" :size="28"></fui-text>
						</view>
					</view>	
				</view>
				<view class="item" v-if="current===1">
					<view class="line">
						<view class="hang">
							<fui-text text="车牌号码：" color="#afafaf" :size="24"></fui-text>
							<platetype :plate_number="item.plate_number" :plate_type="item.plate_type"></platetype>
						</view>
						<view class="hang">
							<fui-text text="停车费用：" color="#afafaf" :size="24"></fui-text>
							<fui-text :text="item.total_fee?`￥${parseNumber(item.total_fee)}`:``" color="#000" :size="28"></fui-text>
						</view>
					</view>
					<view class="line">
						<view class="hang">
							<fui-text text="入场设置：" color="#afafaf" :size="24"></fui-text>
							<fui-text :text="set[item.recovery.entry_set]" color="#000" :size="28"></fui-text>
						</view>
						<view class="hang">
							<fui-text text="追缴方式：" color="#afafaf" :size="24"></fui-text>
							<fui-text :text="item.recovery.recovery_type_txt" color="#000" :size="28"></fui-text>
						</view>
					</view>
					<view class="line">
						<view class="hang">
							<fui-text text="出场设置：" color="#afafaf" :size="24"></fui-text>
							<fui-text :text="set[item.recovery.exit_set]" color="#000" :size="28"></fui-text>
						</view>
						<view class="hang">
							<fui-text text="发送消息：" color="#afafaf" :size="24"></fui-text>
							<fui-text :text="msg[item.recovery.msg]" color="#000" :size="28"></fui-text>
						</view>
					</view>
					<view class="line">
						<view class="hang">
							<fui-text text="追缴状态：" color="#afafaf" :size="24"></fui-text>
							<fui-tag text="追缴成功" v-if="item.recovery.pay_id" type="success"></fui-tag>
							<fui-tag text="正在追缴" v-else background="#CCCCCC" color="#fff"></fui-tag>
						</view>
					</view>
				</view>
			</fui-list-cell>
		</fui-list>
		<fui-empty v-if="list.length===0" :src="`${baseUrl}assets/img/miniapp/empty.png`" title="暂无数据!" :marginTop="200"></fui-empty>
		<filter :param="param" @confirm="doSubmit"></filter>
		<fui-modal :show="act.show" descr="请选择操作" :buttons="buttons[segmented_type[current]]" :radius="16" :maskClosable="true" direction="column" @click="clickButton" @cancel="cancelButton"></fui-modal>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import {formatDuration,parseNumber} from '@/utils/util.js'
	import platetype from '@/components/common/platetype.vue';
	import filter from '@/components/common/filter.vue';
	export default {
		components:{
			platetype:platetype,
			filter:filter
		},
		data() {
			return {
				baseUrl:baseUrl,
				segmented:['逃费记录','追缴记录'],
				segmented_type:['evading','recovery'],
				statusColor:{'6':'#ffdd60','7':'red'},
				set:{0:'不予处理',1:'付费后开闸',2:'岗亭确认开闸'},
				msg:{0:'否',1:'通知管理员'},
				current:0,
				list:[],
				page:1,
				endData:false,
				param:{
					plate_number:'',
					starttime:'',
					endtime:''
				},
				act:{
					show:false,
					index:'',
					item:''
				},
				buttons:{
					evading:[
						{
							text: '订单详情',
							background: '#22b2ff',
							value:'edit'
						},{
							text: '配置追缴',
							background: '#FFB703',
							value:'set'
						},{
							text: '免费出场',
							background: '#1ab445',
							value:'free'
						}
					],
					recovery:[
						{
							text: '订单详情',
							background: '#22b2ff',
							value:'edit'
						},{
							text: '取消追缴',
							background: '#e24814',
							value:'cancel'
						}
					]
				}
			}
		},
		onLoad(e) {	
			this.getList();
		},
		onReachBottom() {
			this.getList();
		},
		onPullDownRefresh() {
			this.list=[];
			this.page=1;
			this.endData=false;
			this.getList(function(){
				uni.stopPullDownRefresh();
			});
		},
		methods: {
			...methods,
			formatDuration,
			parseNumber,
			changeSegmented:function(e){
				this.current=e.index;
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getList();
			},
			doSubmit:function(param){
				this.param=param;
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getList();
			},
			getList:function(callback=false){
				this.showPopup=false;
				if(this.endData){
					this.$msg('已经到底了');
					return;
				}
				this.$get('parking/records/recovery',{
					...this.param,
					type:this.segmented_type[this.current],
					page:this.page
				},true).then(res=>{
					this.list=this.list.concat(res);
					this.page++;
					if(res.length<10){
						this.endData=true;
					}	
					if(callback){
						callback();
					}
				});
			},
			showButton:function(item,index){
				this.act={
					show:true,
					item:item,
					index:index
				}
			},
			clickButton:function(e){
				let index=this.act.item.index;
				let records_id=this.act.item.id;
				if(e.value=='edit'){
					this.$navigateTo('parking/records/detail?records_id='+records_id);
				}
				if(e.value=='set'){
					this.$navigateTo('parking/records/setrecovery?records_id='+records_id);
				}
				if(e.value=='free'){
					uni.showModal({
						content:'您确定要将该条逃费记录设置为免费出场吗？',
						success:(e)=>{
							if(e.confirm){
								this.$post('parking/records/free',{id:records_id},true,true).then(res=>{
									this.list.splice(index,1);
								});
							}
						}
					});
				}
				if(e.value=='cancel'){
					let recovery_id=this.act.item.recovery.id;
					uni.showModal({
						content:'您确定要取消追逃这条逃费记录吗？',
						success:(e)=>{
							if(e.confirm){
								this.$post('parking/records/cancel-recovery',{id:recovery_id},true,true).then(res=>{
									this.list.splice(index,1);
								});
							}
						}
					});
				}
				this.cancelButton();
			},
			cancelButton:function(){
				this.act={
					show:false,
					item:'',
					index:''
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
.item{
	display: flex;
	flex-wrap: wrap;
	.line{
		display: flex;
		justify-content: space-between;
		align-items: center;
		width:100%;
		height: 60rpx;
		.hang{
			width: 50%;
			display: flex;
			align-items: center;
		}
	}
}
</style>